package tech.aistar.controller.collecte;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import tech.aistar.entity.Collecte;
import tech.aistar.entity.UserInfo;
import tech.aistar.service.center.IUserInfoService;
import tech.aistar.service.collecte.ICollecteService;
import tech.aistar.service.collecte.ICollectesViewService;
import tech.aistar.service.services.IService;
import tech.aistar.service.services.IServicesListService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/9/29 0029.
 */
@Controller
@RequestMapping("/collection")
@SuppressWarnings("all")
public class Collectecontroller {
    @Autowired
    private ICollecteService collecteService;

    @Autowired
    private ICollectesViewService collectesViewService;

    @Autowired
    private IUserInfoService userInfoService;



    @Autowired
    private IService service;

    @Autowired
    private IServicesListService servicesListService;

        @RequestMapping("/list")
        public String list(Model model, HttpSession session, HttpServletRequest request, String userinfoId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize){

            Integer uid = (Integer) session.getAttribute("userinfoId");
            //分页
            PageInfo<Collecte> pageInfo = collecteService.findAll(uid,Integer.valueOf(pageNum),Integer.valueOf(pageSize));
            List<Collecte> collecteList =collecteService.coluserFindOne(uid);





            List<UserInfo> userInfos = new ArrayList<>();
            //根据服务者的id 获取服务者的姓名
            for (int i = 0; i < collecteList.size(); i++) {

                UserInfo userInfo = userInfoService.findById(collecteList.get(i).getServicesId());
//                userInfo.setId(collecteList.get(i).getServicesId());
                userInfos.add(userInfo);
            }





            model.addAttribute("userInfos",userInfos);
            model.addAttribute("collecteList",collecteList);
            model.addAttribute("pageInfo",pageInfo);
            return "collection/collection";

        }
}
